package au.com.centrumsystems.hudson.plugin.buildpipeline;

import hudson.model.AbstractProject;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;

import java.util.List;

import au.com.centrumsystems.hudson.plugin.util.BuildUtil;

public class ProjectGrid extends GridForm<HeaderForm, ProjectForm> {

    public static class Builder
    extends GridForm.Builder<HeaderForm, ProjectForm> {

        private final Provider<ProjectForm.Builder> builderProvider;

        @Inject
        public Builder(ProjectGrid.Factory factory, Provider<ProjectForm.Builder> builderProvider) {
             super(factory);
             this.builderProvider = builderProvider;
        }

        public Builder setRoot(AbstractProject<?,?> project) {
            return (ProjectGrid.Builder)
                setHeader(new HeaderForm())
                .setRoot(
                    builderProvider.get()
                        .setProject(project)
                        .build()
                );
        }
    }

    public interface Factory extends GridForm.Factory<HeaderForm, ProjectForm> {

        GridForm<HeaderForm, ProjectForm> create(HeaderForm header, List<ColumnForm<ProjectForm>> columns);
    }

    @Inject
    public ProjectGrid(@Assisted HeaderForm header, @Assisted List<ColumnForm<ProjectForm>> columns) {
        super(header, columns, "project-pipeline");
    }
}

